package Demo02.controller;

import Demo02.domain.Student;
import Demo02.service.StudentServiceImpl;

import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;


public class StudentController {
    public static void main(String[] args) {
        StudentController sc=new StudentController();
        sc.findById();

    }
    private StudentServiceImpl service=new StudentServiceImpl();
    /*
     查询所有学生信息
    */
    public void findAll(){
        ArrayList<Student>list=service.findAll();
        for (Student stu : list) {
            System.out.println(stu);
        }
    }
    /*
    条件查询,根据id查询学生信息
     */
    public void findById(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入学生的id");
        Student stu = service.findById(sc.nextInt());
        System.out.println(stu);
    }
    /*
        新增学生信息
     */
    public void insert(){
        Student stu=new Student(5,"小明",27,new Date());
        int result = service.insert(stu);
        if(result!=0){
            System.out.println("新增成功");
        }else {
            System.out.println("新增失败");
        }
    }
    /*
       修改学生信息
     */

    public void update(){
        Student stu=service.findById(5);
        stu.setName("周七七");
        int result = service.update(stu);
        if(result!=0){
            System.out.println("修改学生信息成功");
        }else{
            System.out.println("修改学生信息失败");

        }
    }
    /*
        删除学生信息
     */
    public void delete(){
        int result = service.delete(5);
        if(result!=0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }

    }
}
